<?php

/**
 *
 *
 * @version $Id: SubMenu.php,v 1.2 2011-06-17 04:43:21 herve Exp $
 * @copyright 2011
 */

/**
 *
 *
 */
class SubMenu extends CWidget {

	public $items = null;
	public $model = null;
	public $withText = true;

	public function run()
	{
		$submenu =$this->controller->submenu;

		$items = array();

		if ($this->items == null) {
			$this->items = array_keys($submenu);
		}

		$fn = "buildWithoutText";
		if ($this->withText) {
			$fn = "buildWithText";
		}

		foreach($this->items as $item)
		{
			if (array_key_exists($item, $submenu)) {
				$items[$item] = $this->$fn($submenu[$item]);
			}
		}

		$this->render('subMenu', array (
			'items' => $items
		));
	}

	private function buildWithText($submenu)
	{
		if (isset($submenu['link'])) {
			return CHtml::linkButton(CHtml::image($submenu['icon']) . "&nbsp;" . $submenu['label'], $submenu['link']);
		}else{
			return CHtml::link(CHtml::image($submenu['icon']) . "&nbsp;" . $submenu['label'], $submenu['href']);
		}
	}

	private function buildWithoutText($submenu)
	{
		if (isset($submenu['link'])) {
			return CHtml::linkButton(CHtml::image($submenu['icon'], $submenu['label']), $submenu['link']);
		}else{
			return CHtml::link(CHtml::image($submenu['icon'], $submenu['label']), $submenu['href']);
		}
	}
}


?>